﻿using FB.Enums;
using FB.Membership;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Web.Security;

namespace FB.Extensions
{
    public static class MembershipProviderExtensions
    {
        /// <summary>
        /// Update AE password for FIS2
        /// </summary>
        /// <param name="membership"></param>
        /// <param name="NewPassword"></param>
        /// <param name="FIS2ConnStr"></param>
        public static void ResetFIS2Password(this AspNetMembershipProviderWrapper membership, MembershipUser user, string NewPassword, string FIS2ConnStr)
        {
            using (var SqlConn = new SqlConnection(FIS2ConnStr))
            {
                var sql = @"UPDATE dbo.USER_MASTER SET [password]=@pwd WHERE [username]=@UserName";

                using (var command = new SqlCommand(sql, SqlConn))
                {
                    command.Parameters.Add(new SqlParameter("@UserName", user.UserName));
                    command.Parameters.Add(new SqlParameter("@pwd", NewPassword));
                    command.Connection.Open();
                    command.ExecuteNonQuery();
                }
            }

        }
    }
}
